/**
 * Created by xuan on 15/12/23.
 */
define(function (require) {
    var angular = require('angular');
    var _ = require('underscore');
    angular.module('roleCommon', [])
        .filter('applicationFilter', function () {
            return function (input, filterApplication) {
                return _.filter(input || [], function (item) {
                    return filterApplication ? (item.Application == filterApplication) : true
                });
            }
        }).filter('contractFilter', function () {
            return function (input, filterContract) {
                return _.filter(input || [], function (item) {
                    return filterContract ? ((item.total_num - item.use_num) > 0) : true;
                });
            }
        })
        .controller('roleCommonCtrl', ['$scope', function ($scope) {
            /* 局部变量 start */

            /* 局部变量 end */

            /* $scope变量 start */
            $scope.applicationData = [
                {
                    text: '全部',
                    code: ''
                },
                {
                    text: '秒杀活动',
                    code: '5020'
                },
                {
                    text: '认筹理财',
                    code: '5021'
                },
                {
                    text: '微楼书',
                    code: '5001'
                },
                {
                    text: '全民营销',
                    code: '5003'
                },
                {
                    text: '小蜜蜂',
                    code: '5008'
                },
                {
                    text: '移动销售',
                    code: '5002'
                },
                {
                    text: '云Call客',
                    code: '5030'
                }
            ];
            $scope.filterApplication = '';

            $scope.calUseNum = function (application) {
                return _.reduce(application.contracts, function(memo, item){ return memo + parseInt(item.use_num); }, 0);
            };
            $scope.calCanUseNum = function (application) {
                return _.reduce(application.contracts, function(memo, item){ return memo + (parseInt(item.total_num)-parseInt(item.use_num)) }, 0);
            };


            /* $scope变量 end */

            /* $scope变量 watch start */

            /* $scope变量 watch end */


            /* $scope方法 start */

            /* $scope方法 end */

            // init
        }]);
});